package com.nl.sort;

import java.util.Arrays;

/**
 * 对有限的数据排序，需求复杂度O(N),可以使用额外空间
 *
 */
public class OnAgeSort {

	private static final int MAX_AGE = 200;

	public static void sortAge(int[] ages) {
		
		int[] maxages = new int[MAX_AGE];
		for(int i=0;i<ages.length;i++){
			maxages[ages[i]]++;
		}
		
		int index = 0;
		for(int i=0;i<MAX_AGE;i++){
			for(int j=0;j<maxages[i];j++){
				ages[index++] = i;
			}
		}
	}
	public static void main(String[] args) {
		int[] ages = new int[]{12,3,90,23,100,100};
		sortAge(ages);
		System.out.println(Arrays.toString(ages));
	}

}
